home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
524
/
524.xpi
/
chrome
/
mid.jar
/
content
/
midGTransOverlay.js
< prev
next >
Wrap
Text File
|
2009-09-16
|
3KB
|
104 lines
generalPrefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
window.addEventListener("load", googTransInit, false);
var selection = '';
var trans = '';
function googTransInit() {
var ifrdoc = document.getElementById("mid_google_iframe").contentDocument;
if (this.notFirst) {
return;
}
var currentLocale = generalPrefs.getCharPref("general.useragent.locale");
document.getElementById("mid_mainbrowsercontextpopup").addEventListener("popupshowing", ongoogTransPopup, false);
this.notFirst = true;
// completely moron idea to set the source to the locale:
// document.getElementById("mid_google_iframe").contentDocument.getElementById('src').value=currentLocale; hu in win hu_HU in Linux
ifrdoc.getElementById("google_translate").value = mid_mud.util.getLocaleString("translate");
ifrdoc.getElementById("results_title").innerHTML = mid_mud.util.getLocaleString("translation");
}
function ongoogTransPopup(event) {
if (event.target.id != 'mid_mainbrowsercontextpopup') return;
var popupnode = document.popupNode;
var nodeLocalName = popupnode.localName.toLowerCase();
if ((nodeLocalName == "textarea") || (nodeLocalName == "input" && popupnode.type == "text")) {
selection = trim(popupnode.value.substring(popupnode.selectionStart, popupnode.selectionEnd));
} else {
if (nodeLocalName == "img") {
if (popupnode.title)
selection = popupnode.title;
else if (popupnode.alt)
selection = popupnode.alt;
else
selection = '';
} else {
var focusedWindow = document.commandDispatcher.focusedWindow;
selection = trim(focusedWindow.getSelection().toString());
}
}
if (selection != '') {
document.getElementById("translate_main").disabled = false;
} else {
document.getElementById("translate_main").disabled = true;
}
}
function mid_googleTranslate() {
var ifrdoc = document.getElementById("mid_google_iframe").contentDocument;
if (selection != '') {
ifrdoc.getElementById("source").value = selection;
ifrdoc.forms[0].onsubmit();
} else return;
var viewitem = document.getElementById("mid_viewpopupgoogletranslatoritem");
if ( viewitem.getAttribute("checked") == "false" ) {
viewitem.doCommand();
}
}
function googleTranslateView() {
var gtSplitter = document.getElementById("mid_editor_splitter");
var gt = document.getElementById("mid_google_iframe");
if (gt.getAttribute("collapsed") == "true") {
document.getElementById("mid_viewpopupgoogletranslatoritem").setAttribute("checked", "true");
gt.setAttribute("collapsed", "false");
gtSplitter.setAttribute("collapsed", "false");
} else {
document.getElementById("mid_viewpopupgoogletranslatoritem").setAttribute("checked", "false");
gt.setAttribute("collapsed", "true");
gtSplitter.setAttribute("collapsed", "true");
}
mid_mud.layoutManager.checkSideBar();
}
function trim(str) {
var x = str;
x = x.replace(/^\s*(.*)/, "$1");
x = x.replace(/(.*?)\s*$/, "$1");
return x;
}